<?php

use support\utils\JwtAuth;

/**
 * 获取当前登录用户
 */
function getCurrentInfo()
{
    if (!request()) {
        return false;
    }
    $header = request()->header(config('genadmin.cross.token_name', 'Authori-zation'));
    if ($header) {
        $token = trim($header);
        if ($token !== 'null' && $token !== '') {
            $key = config('genadmin.cross.jwt_key', 'sai_admin');
            $jwt = new JwtAuth($key);
            [$id, $username, $type] = $jwt->parseToken($token);
            return compact('id', 'username', 'type');
        } else {
            return false;
        }
    } else {
        return false;
    }
}
